/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao.concreto;

import bean.CaracteristicasConsulta;
import interfaces.IDAOFisico2;
import java.math.BigDecimal;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import java.util.ArrayList;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author personal
 */
public class DAOFisico2 implements IDAOFisico2 {

    protected ResourceBundle rb;
    
    
    

    public DAOFisico2() {
        rb = ResourceBundle.getBundle("sql.sqlDiagnosticoFuerza");
    }

    public String insertarSaltabilidad(Connection conn, CaracteristicasConsulta oCaracteristicasConsulta) {
        String sRetorno = "";
        CallableStatement cllStatement = null;
        try {
            cllStatement = conn.prepareCall("{ ? = call insertar_diagnostico(?,?,?)}");
            cllStatement.setString(1, oCaracteristicasConsulta.getIdConsulta());
            cllStatement.setString(2, oCaracteristicasConsulta.getId_caracteristica());
            cllStatement.setString(3, oCaracteristicasConsulta.getCalificacion());
            cllStatement.registerOutParameter(4, Types.VARCHAR);
            cllStatement.executeUpdate();
            sRetorno = cllStatement.getString(4);

            return sRetorno;
        } catch (NumberFormatException ex) {
            ex.printStackTrace();
        } catch (SQLException ex) {
            ex.printStackTrace();
        } finally {
            try {
                cllStatement.close();
            } catch (SQLException ex) {
                Logger.getLogger(DAOFisico2.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return sRetorno;
    }

    public ArrayList getDiagnosticoFuerzaByPacienteEvaluacion(Connection conn, String paciente, int evaluacion) {
        ArrayList retorno = new ArrayList();

        PreparedStatement ps = null;
        ResultSet rs = null;
        try {


            int i = 1;
            ps = conn.prepareStatement(rb.getString("SQL_DIAGNOSTICO_BY_PACIENTE_EVALUACION"));

            ps.setString(i, paciente);
            i++;
            ps.setBigDecimal(i, new BigDecimal(evaluacion));
            rs = ps.executeQuery();
            while (rs.next()) {
                retorno.add(crearObjeto(rs));
            }

        } catch (SQLException ex) {
            ex.printStackTrace();
            Logger.getLogger(DAOFisico2.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                ps.close();
                rs.close();
            } catch (SQLException ex) {
                Logger.getLogger(DAOFisico2.class.getName()).log(Level.SEVERE, null, ex);
            }

        }
        return retorno;
    }

    private CaracteristicasConsulta crearObjeto(ResultSet rs) throws SQLException {
        CaracteristicasConsulta oCaracteristicasConsulta = new CaracteristicasConsulta();
        
        oCaracteristicasConsulta.setId_paciente(rs.getString("id_paciente"));
        oCaracteristicasConsulta.setId_especialista(rs.getString("id_especialista"));
        oCaracteristicasConsulta.setId_caracteristica(rs.getString("id_caracteristica"));
        oCaracteristicasConsulta.setCod_especialidad(rs.getString("cod_especialidad"));
        oCaracteristicasConsulta.setId_super(rs.getString("id_super"));
        oCaracteristicasConsulta.setCalificacion(rs.getString("calificacion"));
        oCaracteristicasConsulta.setNro_evaluacion(rs.getBigDecimal("nro_evaluacion"));
        return oCaracteristicasConsulta;

    }
}
